
import java.io.File;
import java.util.HashSet;

import brzozowski.Brzozowski;
import helpers.AutomataOperations;
import helpers.FileOperations;
import helpers.HandleHashSet;
import helpers.RunWithTimeOut;
import helpers.Stopwatch;
import hopcroft.Hopcroft_Algorithm;
import moore.Moore_Algorithm;
import automaton.*;
import exceptions.NotDeterministInitalStateException;
import exceptions.NotDeterministTransitionException;
import exceptions.UnknownInitialStateException;
import exceptions.UnknownTerminalStateException;

/***
 * Test without timeout
 * @author LE VAN LINH
 *
 */
public class Console_Test3 {
	public static void main(String[] args) throws UnknownInitialStateException, NotDeterministInitalStateException, NotDeterministTransitionException {
		File root = new File("data");
		String ss="";
		for (File file : root.listFiles()) {
			String filePath = root.getPath() +"/"+file.getName();
			System.out.println("======== Read from file " + file.getName());
			DFA automata = FileOperations.readFile(filePath);
			//automata.printString();
			
			/*ss+=file.getName()+", ";
			/*System.out.println("============================");	
			Stopwatch stop = new Stopwatch();
			System.out.println("Minimal automata using HopCroft's algorithm:");
			
			
			HashSet<HandleHashSet> hopPartitions = Hopcroft_Algorithm.hopCroft(automata);
			ss+="Hopcroft:" + stop.elapsedTime();
			System.out.println("The time for HopCroft's algorithm: " + stop.elapsedTime());
			
			//DFA minAutomata = AutomataOperations.minimizeAutomata(automata, hopPartitions);
			//minAutomata.printString();
			
			System.out.println("Minimal automata using Moore's algorithm:");						
			stop = new Stopwatch();
			HashSet<HandleHashSet> partitions = Moore_Algorithm.moore_Equivalence(automata);
			ss+=", Moore:" + stop.elapsedTime();
			System.out.println("The time for Moore's algorithm : " + stop.elapsedTime());
			
			//DFA minAutomata2 = AutomataOperations.minimizeAutomata(automata, partitions);
			//minAutomata2.printString();
			
			stop = new Stopwatch();
			
			try {
				Brzozowski.doBrzozoski(automata);
			} catch (UnknownTerminalStateException e) {
				System.out.println(e.getMessage());
			}
			ss+=", Brzo:" + stop.elapsedTime()+"\n";
			System.out.println("The time for Brozozowski's algorithm : " + stop.elapsedTime());*/
			
			try {
				Thread thread = new Thread(new RunWithTimeOut(automata,0));
				thread.start();
				thread.join(1800000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		FileOperations.saveFile("run_time.txt", ss);
		
	}
}
